package userlogic

import (
	"context"
	model "gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/model/recharge"

	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/rpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetFirstRechargeOrderLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetFirstRechargeOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetFirstRechargeOrderLogic {
	return &GetFirstRechargeOrderLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 获取首充订单
func (l *GetFirstRechargeOrderLogic) GetFirstRechargeOrder(in *rpc.GetFirstRechargeOrderRequest) (*rpc.GetFirstRechargeOrderResponse, error) {
	// 初始化模型
	orderModel := model.NewRechargeOrderModel(l.ctx, l.svcCtx.Db)
	// 获取首充订单
	order, err := orderModel.GetFirstRechargeOrder(in.UserId)
	if err != nil {
		return nil, err
	}
	// 数据映射
	return &rpc.GetFirstRechargeOrderResponse{
		UserId:    order.UserID,
		Amount:    order.Amount,
		OrderNo:   order.OrderNo,
		CreatedAt: order.CreatedAt,
	}, nil
}
